import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:test_flutter/translation/index.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      theme: ThemeData(
        useMaterial3: false, // 禁用Material3样式
        primarySwatch: Colors.blue,
      ),
      home: const ContentPage(),
      translations: TranslationIndex(),
      locale: const Locale('en', 'US'),
      fallbackLocale: Get.deviceLocale, // 获取系统语言
    );
  }
}

class ContentPage extends StatefulWidget {
  const ContentPage({super.key});

  @override
  State<ContentPage> createState() => _ContentPageState();
}

class _ContentPageState extends State<ContentPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('title'.tr)),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('logged_in'.trParams(
                {'name': 'zhangsan', 'email': 'zhangsan@example.com'})),
            ElevatedButton(
              onPressed: () {
                Get.updateLocale(const Locale('zh', 'CN'));
              },
              child: const Text('切换中文'),
            ),
            ElevatedButton(
              onPressed: () {
                Get.updateLocale(const Locale('en', 'US'));
              },
              child: const Text('切换英文'),
            ),
          ],
        ),
      ),
    );
  }
}
